<template>
	<view class="page addNews">
		<view v-show="ytype==false"  class="form-container mb-30">
			<view class="form-item line-b">
				<view class="label" >姓名<text class="c-ff6">*</text></view>
				<view class="right">
					<input type="text" placeholder="请输入" v-model="m.cname"/>
				</view>
			</view>
		<view v-show="ytype==false"  class="pdtb-30 bg-f fz24 c-ff6 tac" @click="ok">提交</view>
	</view>
	<view v-show="ytype" style="height: 300px;width: 100%;background-color: #ffffff;text-align: center;line-height: 300px;font-size: 20px;">当前二维码已经失效</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id:'',
				info:'',
				lhbb:'',
				m:{	
					id:'',
					cname:'',
					phone:'',
				},
				ytype:false
			}
		},
		onLoad(e) {
			    this.id = uni.getStorageSync('uid');
				this.lhbb = e.lhbb
				this.times = e.times
				this.gettimecs(e.times);
				this.init();
		},
		methods: {
			async gettimecs(e){
				let data = {
					times:e
				}
				let res =  await this.$api.gettimecs(data);
				if(res.data.code==1){
					this.ytype = true
				}
			},
		
			async init(){
				let data = {
					id:this.id
				}
				let res =  await this.$api.getuserinfo(data)
				if(res.data.code==0){
					this.info = res.data.data
					this.m.id = res.data.data.id
					if(res.data.data.cp!=null || res.data.data.cp!=''){
						this.m.cname = res.data.data.cname
						this.m.phone = res.data.data.phone
						this.m.danw = res.data.data.danw
					}
				}else{
					uni.navigateTo({
						url:'/pages/index/index'
					})	
				}	
				
			},
			async ok(){
					if(this.m.cname==='' || this.m.cname===null){
							uni.showToast({
							  title: '请填写司机名称',	
							  icon:'none',
							  duration: 2000
							});
							return false;
					}
					// if(this.m.phone==='' || this.m.phone===null){
					// 		uni.showToast({
					// 		  title: '请填写手机号',	
					// 		  icon:'none',
					// 		  duration: 2000
					// 		});
					// 		return false;
					// }
					this.m.lhbb = this.lhbb
					let res =  await this.$api.addlhyqxlv(this.m)
					if(res.data.code==0){
						// uni.setStorageSync('cdtype', 3);
						uni.navigateTo({
							url:'/pages/my/my'
						})
					}else{
						uni.showToast({
						  title: res.data.msg,	
						  icon:'none',
						  duration: 2000
						});
					}
			}
		}
	}
</script>

<style lang="scss">
.addNews {
	&.page {
		padding: 14upx 0;
		height: auto;
	}
	textarea {
		border: 1upx solid #E1E1E1;
		padding: 10upx;
		border-radius: 10upx;
	}
	.linght{
		height: 60upx;
		line-height: 60upx;
	}
}
</style>
